package com.example.drss.adapter;

import java.util.List;

import com.example.drss.R;
import com.example.drss.itemdata.ItemData;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.view.View.OnClickListener;

public class ListViewAllSellerAdapter extends BaseAdapter {
	
	//可以将布局资源生成一个视图
	LayoutInflater inflater;
	//本例子中是一个Activity
	Context context;
	
	List<ItemData> data;
	
	public ListViewAllSellerAdapter(Context context,List<ItemData> data){
		this.context=context;
		this.data=data;
		inflater=LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data==null?0:data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return data==null?null:data.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	private static class Holderview{
		public TextView textView1;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		
		Holderview holderview=null;
		
		if(convertView==null){
			holderview=new Holderview();
			//1布局资源生成视图对象
			convertView = inflater.inflate(R.layout.listview_icon_allseller, parent, false);
			//2获取视图中的子视图
			holderview.textView1=(TextView)convertView.findViewById(R.id.textView_seller_name);
			//3设置标签Object
			convertView.setTag(holderview);
		}else {
			holderview=(Holderview)convertView.getTag();
		}
		
		//设置数据
		final ItemData itemData=data.get(position);
		holderview.textView1.setText(itemData.getSeller());
        
		//返回视图对象
		return convertView;
	}
	


}
